package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysWxBeforeGroup;
import com.ruoyi.system.service.ISysWxBeforeGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * wx群初步采集Controller
 * 
 * @author ruoyi
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/system/wx_before_group")
public class SysWxBeforeGroupController extends BaseController
{
    @Autowired
    private ISysWxBeforeGroupService sysWxBeforeGroupService;

    /**
     * 查询wx群初步采集列表
     */
    @PreAuthorize("@ss.hasPermi('system:wx_before_group:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysWxBeforeGroup sysWxBeforeGroup)
    {
        startPage();
        List<SysWxBeforeGroup> list = sysWxBeforeGroupService.selectSysWxBeforeGroupList(sysWxBeforeGroup);
        return getDataTable(list);
    }

    /**
     * 导出wx群初步采集列表
     */
    @PreAuthorize("@ss.hasPermi('system:wx_before_group:export')")
    @Log(title = "wx群初步采集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysWxBeforeGroup sysWxBeforeGroup)
    {
        List<SysWxBeforeGroup> list = sysWxBeforeGroupService.selectSysWxBeforeGroupList(sysWxBeforeGroup);
        ExcelUtil<SysWxBeforeGroup> util = new ExcelUtil<SysWxBeforeGroup>(SysWxBeforeGroup.class);
        util.exportExcel(response, list, "wx群初步采集数据");
    }

    /**
     * 获取wx群初步采集详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wx_before_group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysWxBeforeGroupService.selectSysWxBeforeGroupById(id));
    }

    /**
     * 新增wx群初步采集
     */
    @PreAuthorize("@ss.hasPermi('system:wx_before_group:add')")
    @Log(title = "wx群初步采集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWxBeforeGroup sysWxBeforeGroup)throws Exception
    {
        if (sysWxBeforeGroup.getAttribute1()!=null&&sysWxBeforeGroup.getAttribute1().trim().equals("0")){
            //如果是提示加入成功，则成员不可为空
            if (sysWxBeforeGroup.getMember()==null||sysWxBeforeGroup.getMember().trim().isEmpty()){
                throw new Exception("入群成功时，人员不可为空");
            }

            if (sysWxBeforeGroup.getBrandType()==null||sysWxBeforeGroup.getBrandType().trim().isEmpty()){
                throw new Exception("入群成功时，品牌不可为空");
            }

            if (sysWxBeforeGroup.getSubBrand()==null||sysWxBeforeGroup.getSubBrand().trim().isEmpty()){
                throw new Exception("入群成功时，子品牌不可为空");
            }

            if (sysWxBeforeGroup.getPrefixType()==null||sysWxBeforeGroup.getPrefixType().trim().isEmpty()){
                throw new Exception("入群成功时，前缀类别不可为空");
            }

            if (sysWxBeforeGroup.getGroupNumber()==null||sysWxBeforeGroup.getGroupNumber().trim().isEmpty()){
                throw new Exception("入群成功时，群编码不可为空");
            }
        }
        return toAjax(sysWxBeforeGroupService.insertSysWxBeforeGroup(sysWxBeforeGroup));
    }

    /**
     * 修改wx群初步采集
     */
    @PreAuthorize("@ss.hasPermi('system:wx_before_group:edit')")
    @Log(title = "wx群初步采集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWxBeforeGroup sysWxBeforeGroup)throws Exception
    {
        if (sysWxBeforeGroup.getAttribute1()!=null&&sysWxBeforeGroup.getAttribute1().trim().equals("0")){
        //如果是提示加入成功，则成员不可为空
        if (sysWxBeforeGroup.getMember()==null||sysWxBeforeGroup.getMember().trim().isEmpty()){
            throw new Exception("入群成功时，人员不可为空");
        }

            if (sysWxBeforeGroup.getBrandType()==null||sysWxBeforeGroup.getBrandType().trim().isEmpty()){
                throw new Exception("入群成功时，品牌不可为空");
            }

            if (sysWxBeforeGroup.getSubBrand()==null||sysWxBeforeGroup.getSubBrand().trim().isEmpty()){
                throw new Exception("入群成功时，子品牌不可为空");
            }

            if (sysWxBeforeGroup.getPrefixType()==null||sysWxBeforeGroup.getPrefixType().trim().isEmpty()){
                throw new Exception("入群成功时，前缀类别不可为空");
            }

            if (sysWxBeforeGroup.getGroupNumber()==null||sysWxBeforeGroup.getGroupNumber().trim().isEmpty()){
                throw new Exception("入群成功时，群编码不可为空");
            }
    }
        return toAjax(sysWxBeforeGroupService.updateSysWxBeforeGroup(sysWxBeforeGroup));
    }

    /**
     * 删除wx群初步采集
     */
    @PreAuthorize("@ss.hasPermi('system:wx_before_group:remove')")
    @Log(title = "wx群初步采集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysWxBeforeGroupService.deleteSysWxBeforeGroupByIds(ids));
    }
}
